/*
** 2105.c
** 
** Made by (seakage2h)
** Login   <seakage2h@seakage2h-ubuntu>
** 
** Started on  Thu Sep 25 19:55:04 2008 seakage2h
** Last update Sun May 12 01:17:25 2002 Speed Blue
*/

/* #include "2105.h" */
#include <stdio.h>

int main()
{
     int instance;
     char tmp[33];
     int i,k;
     int ip_seg;
     int power2[7] = {2, 4, 8, 16, 32, 64, 128};
		     

     scanf("%d", &instance);
     while(instance){
	  scanf("%s", tmp);
	  for(i = 0; i < 4; i++){
	       for(k = 0, ip_seg = 0; k < 7; k++)
		    if (tmp[k + 8*i] - '0')
			 ip_seg += power2[6 - k];
	       printf("%d", ip_seg + tmp[7 + 8*i] - '0');
	       if (i < 3)
		    putchar('.');
	  }
	  putchar('\n');
	  instance--;
     }
     return 0;
}

